"use strict";
var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
        return typeof obj
    }
    : function(obj) {
        return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
    }
;
window.console = window.console || function() {
    var c = {};
    return c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function() {}
        ,
        c
}(),
    String.prototype.m7trim = function() {
        return void 0 === this ? "" : this.replace(/^\s*/g, "").replace(/\s*$/g, "")
    }
;
var hostUrl = "/"
    , moor7Source = "";
if (document.currentScript)
    hostUrl = (moor7Source = document.currentScript.src).split("javascripts")[0];
else
    for (var m7script = document.getElementsByTagName("script"), i = 0; i <= m7script.length; i++) {
        var m7scriptSrc = m7script[i].src;
        if (-1 < m7scriptSrc.indexOf("javascripts/7moorInit.js")) {
            hostUrl = moor7Source = m7scriptSrc.split("javascripts")[0];
            break
        }
    }
!function() {
    var ie = !(!window.attachEvent || window.opera)
        , wk = /webkit\/(\d+)/i.test(navigator.userAgent) && RegExp.$1 < 525
        , fn = []
        , run = function() {
        for (var i = 0; i < fn.length; i++)
            fn[i]()
    }
        , d = document;
    d.ready = function(f) {
        if (!ie && !wk && d.addEventListener)
            return d.addEventListener("DOMContentLoaded", f, !1);
        if (!(1 < fn.push(f)))
            if (ie)
                !function() {
                    try {
                        d.documentElement.doScroll("left"),
                            run()
                    } catch (err) {
                        setTimeout(arguments.callee, 0)
                    }
                }();
            else if (wk)
                var t = setInterval(function() {
                    /^(loaded|complete)$/.test(d.readyState) && (clearInterval(t),
                        run())
                }, 0)
    }
}();
var clientId = ""
    , otherParams = "";
"string" == typeof qimoClientId && "undefined" != qimoClientId && (clientId = encodeURIComponent(qimoClientId)),
"object" == ("undefined" == typeof qimoClientId ? "undefined" : _typeof(qimoClientId)) && (clientId = qimoClientId.userId || "");
var phoneSystemFrom = ""
    , m7navigator = navigator.userAgent
    , isAndroidFlag = -1 < m7navigator.indexOf("Android") || -1 < m7navigator.indexOf("Linux")
    , isIOSFlag = !!m7navigator.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
isAndroidFlag && (phoneSystemFrom = "android"),
isIOSFlag && (phoneSystemFrom = "ios");
var qimo_config = {
    chatHost: hostUrl,
    accessId: 0,
    language: "zh-CN",
    autoShow: !0,
    m7webchatpage: !1,
    version: "1.0",
    chatPage: hostUrl + "view/moor_chat.html",
    companyConfigUrl: hostUrl + "online",
    urlTitle: encodeURIComponent(document.title),
    fromUrl: encodeURIComponent(window.location.href),
    clientId: clientId,
    location: window.location.host,
    otherParams: otherParams,
    M7CardInfo: {},
    referrer: document.referrer || "",
    videoPage: "https://txrtc.7moor.com/",
    screenSharePage: "https://txtxrtc.7moor.com",
    userBehaviorVideoId: "",
    ubaOnOff: "false",
    sessionLastToPeer: "",
    proxyMsgUrl: "",
    uvpvSwitch: "false",
    sessionInvitation: "0",
    phoneSystemFrom: phoneSystemFrom,
    newMsgNotPop: !1,
    hasInitConfig: !1,
    reInitCallback: void 0,
    refreshUnreopen: !1,
    parseQuerystring: function(queryStr) {
        if ("string" != typeof queryStr)
            return {};
        if ("" === (queryStr = queryStr.m7trim()))
            return {};
        var json = {};
        try {
            for (var pairs = queryStr.split("&"), i = 0; i < pairs.length; i++) {
                var kv = pairs[i].split("=");
                kv[0] && kv[1] && (json[kv[0]] = decodeURIComponent(kv[1]))
            }
        } catch (e) {}
        return json
    }
}
    , href = window.location.href
    , headSimplifyFlag = !1;
if (0 < href.indexOf("?")) {
    var query_arr = href.split("?")[1].split("&");
    try {
        for (var p = 0; p < query_arr.length; p++) {
            var temp = query_arr[p].split("=");
            "headSimplify" == temp[0] && "true" === temp[1] && (headSimplifyFlag = !0)
        }
    } catch (e) {}
}
var simplifyFlag = headSimplifyFlag || "object" == ("undefined" == typeof qimoClientId ? "undefined" : _typeof(qimoClientId)) && qimoClientId.headSimplify;
simplifyFlag && phoneSystemFrom && (qimo_config.chatPage = qimo_config.chatPage.replace("moor_chat.html", "moor_chat_simplify.html")),
"object" == ("undefined" == typeof qimoClientId ? "undefined" : _typeof(qimoClientId)) && qimoClientId.refreshUnreopen && (qimo_config.refreshUnreopen = qimoClientId.refreshUnreopen);
var onlineData = void 0;
!function() {
    var scripts = {
        localInit: "7moorInit.js",
        pcChat: qimo_config.chatHost + "javascripts/QiMoIMSDK-d2f1c90ef3.js",
        externalAPI: qimo_config.chatHost + "javascripts/external_api.js",
        ubaJs: "https://ykf-uba.7moor.com/js/uba.min.js",
        recorderJs: qimo_config.chatHost + "javascripts/recorder.js",
        mobileBackJs: qimo_config.chatHost + "javascripts/mobileBackFunc.js"
    }
        , Configure = {
        init: function() {
            var cookieSid = Configure.getCookie("parent_qimo_sid_" + qimo_config.accessId) || ""
                , data = {
                accessId: qimo_config.accessId,
                unionAccessId: qimo_config.unionAccessId,
                location: encodeURIComponent(window.location.host),
                referrer: document.referrer || "",
                callbackF: "getChatConfig",
                action: "getOnlineStates",
                sid: cookieSid || ""
            };
            this.loadJsonp(qimo_config.companyConfigUrl, data)
        },
        getCookie: function(key) {
            for (var arrCookie = document.cookie.split("; "), i = 0; i < arrCookie.length; i++) {
                var arr = arrCookie[i].split("=");
                if (arr[0] == key)
                    return arr[1]
            }
            return ""
        },
        getInitJsData: function() {
            for (var src, s = document.getElementsByTagName("script"), i = 0, n = s.length; i < n; i++)
                if ((src = s[i].src) && -1 < src.indexOf(scripts.localInit)) {
                    src = src.toLowerCase();
                    break
                }
            if (src && 0 < src.indexOf("accessid=")) {
                var querys = qimo_config.parseQuerystring(src.substr(src.indexOf("?") + 1));
                qimo_config.accessId = querys.accessid,
                    qimo_config.language = "en" === querys.language ? "en" : "zh-CN",
                querys.fromurl && (qimo_config.fromUrl = querys.fromurl),
                querys.autoshow && (qimo_config.autoShow = querys.autoshow),
                "true" === querys.m7webchatpage && (qimo_config.m7webchatpage = !0),
                querys.wap && (qimo_config.wap = querys.wap),
                querys.newmsgnotpop && (qimo_config.newMsgNotPop = querys.newmsgnotpop),
                querys.unionaccessid && (qimo_config.unionAccessId = querys.unionaccessid)
            }
            scripts.pcChat = scripts.pcChat + "?accessId=" + qimo_config.accessId
        },
        addJsElement: function(src) {
            var el = document.createElement("script");
            el.setAttribute("charset", "UTF-8"),
                el.src = src;
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(el, s)
        },
        loadJsonp: function(url, data) {
            var query = function(json) {
                json = json || {};
                var query_arr = [];
                for (var key in json.__ = (new Date).getTime(),
                    json) {
                    var val = json[key];
                    query_arr.push(key + "=" + encodeURIComponent(val))
                }
                return query_arr.join("&").replace(/%20/g, "+")
            }(data)
                , script = document.createElement("script");
            script.type = "text/javascript",
                script.setAttribute("charset", "UTF-8"),
                script.src = url + "?" + query;
            try {
                document.body.appendChild(script)
            } catch (e) {
                document.ready(function() {
                    document.body.appendChild(script)
                })
            }
        },
        loadUbaJs: function() {
            var skey = "qimo_seosource_" + qimo_config.accessId
                , times = 0
                , interval = setInterval(function() {
                times++,
                (Configure.getCookie(skey) || 10 < times) && (Configure.addJsElement(scripts.ubaJs + "?v=" + qimo_config.version),
                    clearInterval(interval))
            }, 100)
        },
        loadVedioJs: function(url) {
            var script = document.createElement("script");
            script.type = "text/javascript",
                script.setAttribute("charset", "UTF-8"),
                script.src = url;
            try {
                document.body.appendChild(script)
            } catch (e) {
                document.ready(function() {
                    document.body.appendChild(script)
                })
            }
        }
    };
    Configure.getInitJsData(),
        Configure.init(),
        window.getChatConfig = function(c) {
            onlineData = c,
            void 0 !== qimo_config.unionAccessId && void 0 !== c.accessId && (qimo_config.accessId = c.accessId),
                "true" !== c.ubaOnOff ? qimo_config.ubaOnOff = "false" : qimo_config.ubaOnOff = c.ubaOnOff,
                "true" !== c.uvpvSwitch ? qimo_config.uvpvSwitch = "false" : qimo_config.uvpvSwitch = c.uvpvSwitch,
                "1" !== c.sessionInvitation ? qimo_config.sessionInvitation = "0" : qimo_config.sessionInvitation = c.sessionInvitation,
                qimo_config.version = c.version,
                qimo_config.companyName = c.companyName,
                qimo_config.account = c.account,
                c.isSessionExist ? qimo_config.sessionLastToPeer = c.sessionToPeer : qimo_config.sessionLastToPeer = "",
            onlineData.pageTitle && qimo_config.m7webchatpage && (document.title = onlineData.pageTitle),
            !0 === onlineData.backJsEnable && Configure.addJsElement(scripts.mobileBackJs),
                !0 !== qimo_config.hasInitConfig ? (Configure.addJsElement(scripts.pcChat + "&v=" + qimo_config.version),
                    Configure.loadUbaJs(),
                    qimo_config.hasInitConfig = !0) : window.qimosdk.reInitChat(onlineData, function() {
                    console.log("切换完成")
                })
        }
        ,
        window.m7InitConfigure = Configure
}();
